package com.duo.exception;

import com.duo.enums.errorcode.BaseCode;
import com.duo.enums.errorcode.StatusCode;
import lombok.Getter;

/**
 * 业务异常
 */
@Getter
@SuppressWarnings(value = "all")
public class BaseException extends RuntimeException {

    /**
     * 状态码
     */
    private int code;

    /**
     * 状态码配套的msg
     */
    private String msg;

    // 手动设置异常
    public BaseException(StatusCode statusCode, String message) {
        super(message);
        this.code = statusCode.getCode();
        this.msg = statusCode.getMessage();
    }

    public BaseException(StatusCode statusCode) {
        super(statusCode.getMessage());
        this.code = statusCode.getCode();
        this.msg = statusCode.getMessage();
    }

    // 默认使用INNER_ERROR的状态码
    public BaseException(String message) {
        super(message);
        this.code = BaseCode.InnerError.getCode();
        this.msg = BaseCode.InnerError.getMessage();
    }

}
